'''
    Tutor user's methods
'''
#-*- coding: UTF-8 -*- 

#import MySQLdb
#import types
from conf import *
from MySqlDBHandle import MySqlDBHandle

class MiniteTime:
    mSQLStatement_minite = "INSERT INTO LU_Minite (Minite_id, Hour_id, Minite_datetime) VALUES"
    mSQLValueStatement_minite ="('%s', '%s', '%s'),"
    mSQLStatement_hour = "INSERT INTO LU_hour (Hour_id, Hour_datetime, Day_date) VALUES"
    mSQLValueStatement_hour ="('%s', '%s', '%s'),"
#    mMiniteID=""
#    mMiniteDateTime=''
    #INSERT INTO `biae`.`lu_hour` (`Hour_id`, `Hour_datetime`, `Day_date`) VALUES ('2012060100', '2012-06-01 00:00:00', '2012-06-01');
    #('201206010000', '2012060100','2012-06-01 00:00:00');
    def InsertTimeToDB(self):
        lYear=2012
        lMonth=6
        lDate=1
        lHour=0
        lMinite=0
        lcDate=30
        for lMonth in range(6,10):
            if lMonth==7 or lMonth==8:
                lcDate=32
            else:
                lcDate=31
            for lDate in range(1,lcDate):
                lValueStatement_hour=''
                lValueStatement_minite=''
                for lHour in range(0,24):
                    lValueStatement_hour += (self.mSQLValueStatement_hour % (str(lYear)+str(lMonth).zfill(2)+str(lDate).zfill(2)+str(lHour).zfill(2), \
                                                                            str(lYear)+'-'+str(lMonth).zfill(2)+'-'+str(lDate).zfill(2)+' '+str(lHour).zfill(2)+':00:00',\
                                                                            str(lYear)+'-'+str(lMonth).zfill(2)+'-'+str(lDate).zfill(2)))
                    for lMinite in range(0,60):
                        lValueStatement_minite+= (self.mSQLValueStatement_minite % (str(lYear)+str(lMonth).zfill(2)+str(lDate).zfill(2)+str(lHour).zfill(2)+str(lMinite).zfill(2), \
                                                                            str(lYear)+str(lMonth).zfill(2)+str(lDate).zfill(2)+str(lHour).zfill(2),\
                                                                            str(lYear)+'-'+str(lMonth).zfill(2)+'-'+str(lDate).zfill(2)+' '+str(lHour).zfill(2)+':'+str(lMinite).zfill(2)+':00'))
                try:
                    self.mSQLStatement_hour += lValueStatement_hour[:len(lValueStatement_hour) - 1]
                    self.mSQLStatement_minite += lValueStatement_minite[:len(lValueStatement_minite) - 1]
                    MySqlDBHandle.execSqlStatement(self.mSQLStatement_hour)
                    MySqlDBHandle.execSqlStatement(self.mSQLStatement_minite)
                except Exception, e:
                    print "Error in TutorUser.py InsertTutorToDB function with " + str(e)
                
                self.mSQLStatement_minite = "INSERT INTO LU_Minite (Minite_id, Hour_id, Minite_datetime) VALUES"
                self.mSQLStatement_hour = "INSERT INTO LU_hour (Hour_id, Hour_datetime, Day_date) VALUES"
                print ("%s success!!!" % (str(lYear)+str(lMonth).zfill(2)+str(lDate).zfill(2)))
                
#            self._insertUserToDB()

#        
#    def _insertUserToDB(self):
#        if self._IsUserIdInDB():
#            return
#        else:
#            try:
#                lSQLStatement = "INSERT INTO LU_tutor (Tutor_name, Weibo_id, genderID, LAST_UPDATE_TIMESTAMP) VALUES (%s, %s, %s, current_timestamp);" \
#                % (self.mName, self.mWeiboId, self.mGender )
#                MySqlDBHandle.execSqlStatement(lSQLStatement)
#            except Exception, e:
#                print "Error in TutorUser.py InsertTutorToDB function with " + str(e)
#                
#    def _IsUserIdInDB(self):
#        lSQLStatement = "SELECT * FROM lu_tutor WHERE Weibo_id = %s;" % self.mWeiboId
#        result = MySqlDBHandle.execSqlStatement(lSQLStatement)
#        if result is None:
#            return False
#        else:
#            return True
    

    
